
#[macro_use]
extern crate mymod;
extern crate hyper;

use std::result::Result::Ok;
use std::string::String;
use mymod::mymod1;
use mymod::mymod2;
use mymod::mymod2::mymod3 as mm3; //别名

fn main() {
    println!("Hello, world!");
    // 引用模块：注意默认文件lib.rs,mod.rs还有目录层次
    mymod1::mymod_str();
    mymod2::mymod2_str();
    mm3::mymod3_str();
    // 加两个数
    test_merge_num();
    // 组合两个字符串
    test_merge_str();
    // 取首个单词
    first_word_test();
    // 引用方式传递可变数组
    array_test();
    // 结构和方法语法，关联函数
    st_fn_test();
    // 引用数组
    runlist();
    // 生命周期，谁最长
    longest_test();
    // 生命周期2
    test_longset1();
    // 结构生命周期
    struct_lifttime();
    test_longest_with_an_announcement();
    // 内部函数
    inside_fn();
    // 闭包测试
    test_closures();
    //结构体带泛型闭包
    test_cacher();
    // 迭代器循环 测试
    text_iterator();
    // 线程和通道 test
    // thread_channel_test();
    // 继承和面向对象
    test_object();
    // 测试宏
    test_macro();
    // base64测试
    base64_test();
    // pi算法测试
    pi_count_test();
    // 格式化打印测试
    print_test_master();
}

/// Adds one to the number given.
///
/// # Examples
///
/// ```
/// let x:i32=56;
/// let y:i32=73;
/// let z=addnumber(x,y);
/// println!("{:?}", z);
/// ```
fn addnumber(x:i32,y:i32)->i32{
    x+y
}

fn test_merge_num(){
    let x:i32=56;
    let y:i32=73;
    let z=addnumber(x,y);
    println!("{:?}", z);
}

fn addstr(s1:String, s2:String) -> String{
    s1+&s2
}

fn test_merge_str(){
    let s1:String = String::from("hello fuck world!");
    let s2:String = String::from(" deam!");
    let s3 = addstr(s1,s2);
    println!("{:?}", s3);
}

fn first_word(s: &String) -> &str {
    let bytes = s.as_bytes();
    for (i, &item) in bytes.iter().enumerate() {
        if item == b' ' {
            return &s[0..i];
        }
    }
    &s[..]
}
// 取首个单词
fn first_word_test(){
    let s22 = String::from("Здравствуйте Здравс");
    let s23 = first_word(&s22);
    println!("{:?}", s23);
}

fn editarray(a:&mut [i32])->&[i32]{
    a[0]=3;
    a
}

fn array_test(){
    let mut a:[i32;5]=[1,2,3,4,5];
    editarray(&mut a);
    println!("{:?}", a);
}

#[derive(Debug)]
struct Rectangle {
    width: u32,
    height: u32,
}

impl Rectangle {
    fn area(&self) -> u32 {
        self.width * self.height
    }
    fn area100(&self) -> u32 {
        self.width * self.height + 100
    }
}
impl Rectangle {
    fn area200(&self) -> u32 {
        self.width * self.height + 200
    }
}
impl Rectangle {
    fn area300(x:&Rectangle) -> u32 {
        x.width * x.height + 300
    }
}

fn st_fn_test(){
    let rect = Rectangle{
        width:10,
        height:20,
    };
    let r1 = rect.area();
    println!("{:?}", r1);
    let r1 = rect.area100();
    println!("{:?}", r1);
    let r1 = rect.area200();
    println!("{:?}", r1);
    let r1 = Rectangle::area300(&rect);
    println!("{:?}", r1);
}

pub fn runlist(){
    let mut v = vec![100, 32, 57, 23, 34, 45, 76]; // 可变更遍历
    v.push(123);
    for i in &mut v {
        *i += 50; // 使用 += 运算符之前必须使用解引用运算符（*）获取 i 中的值。
        println!("VEC v = {:?}", i);
    }
    v.push(999);
    println!("VEC = {:?}", v);
}

fn longest<'a>(x: &'a str, y: &'a str) -> &'a str {
    if x.len() > y.len() {
        x
    } else {
        y
    }
}

// 生命周期测试'a
fn longest_test(){
    let s31 = String::from("FK X8");
    let s32 = String::from("OF ");
    let s33 = longest(&s31, &s32);
    println!("生命周期测试'a ：{:?}", s33);
}

// fn longest1<'a,'b>(x: &'a str, y: &'b str) -> &str { // 这个是编译不通的
//     if x.len() > y.len() {
//         x
//     } else {
//         y
//     }
// }

fn test_longset1() {
    let string1 = String::from("long string is long");
    let string2 = String::from("xyz");
    let result = longest(string1.as_str(), string2.as_str());
    println!("The longest string is {}", result);
    // println!("The longest string is {} -- {}", string1, string2);
}

struct ImportantExcerpt<'a> {
    part: &'a str,
}

fn struct_lifttime() {
    println!("测试结构生命周期 ========== ");
    let name = String::from(" www lll ");
    let novel = String::from("Call me Ishmael. Some years ago...");
    let first_sentence = novel.split('.')
        .next()
        .expect("Could not find a '.'");
    let i = ImportantExcerpt { part: first_sentence };
    println!("{:?}", i.part);
    println!("{:?}", i.level());
    println!("{:?}", i.announce_and_return_part(&name));
}

impl<'a> ImportantExcerpt<'a> {
    fn level(&self) -> i32 {
        3
    }
    fn announce_and_return_part(&self, announcement: &str) -> &str {
        println!("Attention please: {}", announcement);
        self.part
    }
}

use std::fmt::Display;

fn longest_with_an_announcement<'a, T>(x: &'a str, y: &'a str, ann: T) -> &'a str
    where T: Display
{
    println!(" 打印 ann Announcement! ： {}", ann);
    if x.len() > y.len() {
        x
    } else {
        y
    }
}

fn test_longest_with_an_announcement(){
    let x = String::from("wwwww == xxx111");
    let y = String::from("wwwww == yyy222");
    let rs = longest_with_an_announcement(&x, &y, 32);
    println!(" 测试  结构体带泛型 测试最长字符串： {:?}", rs);
}

// 内部函数
fn inside_fn(){
    fn equal_to_x(z: i32) -> bool { z == 10 }
    let r2 = equal_to_x(13);
    println!("内部函数测试：equal_to_x = {:?}", r2);
}
// 闭包
fn test_closures() {
    let x = 4;
    let equal_to_x = |z| z == x;
    let y = 4;
    let r = equal_to_x(y);
    println!("闭包测试：{:?}", r);
}

struct Cacher<T>
    where T: Fn(u32) -> u32
{
    calculation: T,
    value: Option<u32>,
}

impl<T> Cacher<T>
    where T: Fn(u32) -> u32
{
    fn new(calculation: T) -> Cacher<T> {
        Cacher {
            calculation,
            value: None,
        }
    }

    fn value(&mut self, arg: u32) -> u32 {
        match self.value {
            Some(v) => v,
            None => {
                let v = (self.calculation)(arg);
                self.value = Some(v);
                v
            },
        }
    }
}

fn test_cacher(){
    let mut expensive_result = Cacher::new(|num| {
        println!(" 在计算 ...");
        num
    });
    println!(" 结构体带泛型和闭包： {:?}", expensive_result.value(32));
}

fn iterator_sum() {
    let v1 = vec![1, 2, 3, 4, 5];
    let v1_iter = v1.iter();
    let total: i32 = v1_iter.sum();
    println!("迭代器循环+ ： {:?}", total);
}

fn iterator_map_collect(){
    let v1: Vec<i32> = vec![1, 2, 3, 4, 5];
    let v2: Vec<_> = v1.iter().map(|x| x + 1).collect();
    println!("迭代器循环 每个数值+1 ： {:?}", v2);
}

fn text_iterator(){
    iterator_sum();
    iterator_map_collect();
    Shoe::filters_by_size();
    calling_next_directly();
    using_other_iterator_trait_methods();
}

#[derive(PartialEq, Debug)]
pub struct Shoe {
    size: u32,
    style: String,
}
// 闭包迭代获取环境
impl Shoe{
    pub fn shoes_in_my_size(shoes: Vec<Shoe>, shoe_size: u32) -> Vec<Shoe> {
        shoes.into_iter() // 获取 v1 所有权并返回拥有所有权的迭代器
            .filter(|s| s.size == shoe_size) // 过滤器 有个闭包
            .collect() // 再组合迭代
    }

    pub fn filters_by_size() {
        let shoes = vec![
            Shoe { size: 10, style: String::from("sneaker") },
            Shoe { size: 13, style: String::from("sandal") },
            Shoe { size: 10, style: String::from("boot") },
        ];

        let in_my_size = Shoe::shoes_in_my_size(shoes, 10);
        println!("迭代循环测试-新shoesize=10的才被选出来：{:?}", in_my_size);
        // assert_eq!(
        //     in_my_size,
        //     vec![
        //         Shoe { size: 10, style: String::from("sneaker") },
        //         Shoe { size: 10, style: String::from("boot") },
        //     ]
        // );
    }
}

#[derive(Debug)]
struct Counter {
    count: u32,
}

impl Counter {
    fn new() -> Counter {
        Counter { count: 0 }
    }
}

impl Iterator for Counter {
    type Item = u32;

    fn next(&mut self) -> Option<Self::Item> {
        self.count += 1;

        if self.count < 6 {
            Some(self.count)
        } else {
            None
        }
    }
}

fn calling_next_directly() {
    let mut counter = Counter::new();
    println!("自定义迭代器6以内迭代：{:?}", counter);
    assert_eq!(counter.next(), Some(1));
    assert_eq!(counter.next(), Some(2));
    assert_eq!(counter.next(), Some(3));
    assert_eq!(counter.next(), Some(4));
    assert_eq!(counter.next(), Some(5));
    assert_eq!(counter.next(), None);
    println!("自定义迭代器6以内迭代：{:?}", counter);
}


fn using_other_iterator_trait_methods() {
    let sum: u32 = Counter::new().zip(Counter::new().skip(1))
                                 .map(|(a, b)| a * b)
                                 .filter(|x| x % 3 == 0)
                                 .sum();
    println!("迭代 先杂合，再map，再过滤，最后总和 ： {:?}", sum);
}

fn thread_channel_test(){
    thread_channel();
    thread_channel_2();
    thread_channel_3();
    thread_share_01();
}

use std::thread;
use std::sync::mpsc;
fn thread_channel() {
    let (tx, rx) = mpsc::channel();

    thread::spawn(move || {
        let val = String::from("hi");
        tx.send(val).unwrap();
    });

    let received = rx.recv().unwrap();
    println!("Got: {}", received);
}


// use std::thread;
// use std::sync::mpsc;
use std::time::Duration;

fn thread_channel_2() {
    let (tx, rx) = mpsc::channel();

    thread::spawn(move || {
        let vals = vec![
            String::from("hi"),
            String::from("from"),
            String::from("the"),
            String::from("thread"),
        ];

        for val in vals {
            tx.send(val).unwrap();
            thread::sleep(Duration::from_secs(1));
        }
    });

    for received in rx {
        println!("Got: {}", received);
    }
}
// 线程通道
fn thread_channel_3(){
    let (tx, rx) = mpsc::channel();

    let tx1 = mpsc::Sender::clone(&tx);
    thread::spawn(move || {
        let vals = vec![
            String::from("hi"),
            String::from("from"),
            String::from("the"),
            String::from("thread"),
        ];

        for val in vals {
            tx1.send(val).unwrap();
            thread::sleep(Duration::from_secs(1));
        }
    });

    thread::spawn(move || {
        let vals = vec![
            String::from("more"),
            String::from("messages"),
            String::from("for"),
            String::from("you"),
        ];

        for val in vals {
            tx.send(val).unwrap();
            thread::sleep(Duration::from_secs(1));
        }
    });

    for received in rx {
        println!("Got: {}", received);
    }
}

// 线程间共享
// use std::thread;
use std::sync::{Mutex, Arc};

fn thread_share_01() {
    let counter = Arc::new(Mutex::new(0));
    let mut handles = vec![];

    for _ in 0..10 {
        let counter = Arc::clone(&counter);
        let handle = thread::spawn(move || {
            let mut num = counter.lock().unwrap();

            *num += 1;
        });
        handles.push(handle);
    }

    for handle in handles {
        handle.join().unwrap();
    }

    println!("多线程共享数据实例 Result: {}", *counter.lock().unwrap());
}

// 有关面向对象的代码

pub struct AveragedCollection {
    list: Vec<i32>,
    average: f64,
}

impl AveragedCollection {
    pub fn add(&mut self, value: i32) {
        self.list.push(value);
        self.update_average();
    }

    pub fn remove(&mut self) -> Option<i32> {
        let result = self.list.pop();
        match result {
            Some(value) => {
                self.update_average();
                Some(value)
            },
            None => None,
        }
    }

    pub fn average(&self) -> f64 {
        self.average
    }

    fn update_average(&mut self) {
        let total: i32 = self.list.iter().sum();
        self.average = total as f64 / self.list.len() as f64;
    }
}

// 对象 - 继承

fn test_object(){
    test_object01();
}

extern crate rust_gui;
use rust_gui::{Draw, Screen, Button};

#[derive(Debug)]
pub struct SelectBox {
    width: u32,
    height: u32,
    options: Vec<String>,
}

impl Draw for SelectBox {
    fn draw(&self) {
        println!("screen draw SelectBox {:?}", self);
    }
}

fn test_object01() {
    let screen = Screen {
        components: vec![
            Box::new(SelectBox {
                width: 75,
                height: 10,
                options: vec![
                    String::from("Yes"),
                    String::from("Maybe"),
                    String::from("No")
                ],
            }),
            Box::new(Button {
                width: 50,
                height: 10,
                label: String::from("OK"),
            }),
        ],
    };

    screen.run();
}



fn test_macro(){
    test_macro_str();
}

// 声明式宏测试
#[macro_export]
macro_rules! strfrom {
    ( $( $x:expr ),* ) => {
        {
            let mut temp_str = String::from("");
            $(
                temp_str.push_str($x);
                temp_str.push(' ');
            )*
            temp_str
        }
    };
}

fn test_macro_str(){
    let s = strfrom!["my name is macro","namne","sheet","fuck","off", "S-1"];
    let s2 = strfrm!["my name is macro","namne","sheet","fuck","off", "S-2"];
    println!("简单宏测试构成mut的字符串变量 = {:?}", s);
    println!("简单宏测试构成mut的字符串变量 2 = {:?}", s2);
}

// 过程式宏测试  以后再学习


// base64 加密解密

pub fn base64_test(){
    let b64_en = mymod1::base64encode(&String::from("asdfd流啊荒野大34242344frer34如werr3r登革热广告1"));
    println!("base64_en = {:?}", b64_en);
    let b64_de = mymod1::base64decode(&b64_en);
    println!("base64_de = {:?}", b64_de);
}

pub fn pi_count_test(){
    //pi_count_test_01();
    pi_count_test_02();
    pi_count_test_04();
}

// pi计算算法测试
pub fn pi_count_test_01(){
    let t = 1000000;
    let pi = mymod2::pi_01(t);
    println!("pi is {:?}", pi);
}

pub fn pi_count_test_02(){
    let t = 100000;
    let pi = mymod2::pi_02(t);
    println!("pi is {:?}", pi);
}

pub fn pi_count_test_04(){
    let t = 99999999;
    let pi = mymod2::pi_04(t);
    println!("pi is {:?}", pi);
}

use std::io::{self, Write};
use hyper::Client;
use hyper::rt::{self, Future, Stream};

pub fn callhttp() {
    rt::run(rt::lazy(|| {
        // still inside rt::run...
        // let client = Client::new();

        // let uri = "http://httpbin.org/ip".parse().unwrap();

        // client
        //     .get(uri)
        //     .map(|res| {
        //         println!("Response: {}", res.status());
        //     })
        //     .map_err(|err| {
        //         println!("Error: {}", err);
        //     })
        //------------------------
        let client = Client::new();

        let uri = "http://httpbin.org/ip".parse().unwrap();

        client
            .get(uri)
            .and_then(|res| {
                println!("Response: {}", res.status());
                res
                    .into_body()
                    // Body is a stream, so as each chunk arrives...
                    .for_each(|chunk| {
                        io::stdout()
                            .write_all(&chunk)
                            .map_err(|e| {
                                panic!("example expects stdout is open, error={}", e)
                            })
                    })
            })
            .map_err(|err| {
                println!("Error: {}", err);
            })
    }));
    // --------------------------
}

// =======================打印测试
use mymod::print_format_mod;
use mymod::compound_type_test;
use mymod::literals_and_operators;
use mymod::tuples;
use mymod::arrays_and_slices;
use mymod::mod_enum_test;
use mymod::mod_enum_test2;
use mymod::clike_test;
use mymod::structuresx;
use mymod::testcase_linked_list_test;
use mymod::constants_test;
use mymod::variable_bindings_test;
use mymod::mutability_test;
use mymod::scope_and_shadowing_test;
use mymod::declare_first_test;
use mymod::casting_test;
use mymod::literals_test;
use mymod::inference_test;
use mymod::aliasing_test;
use mymod::conversion_from_and_into_test;
use mymod::to_and_from_strings;
use mymod::expressions_test;
use mymod::flow_control_test;
use mymod::match_test;
use mymod::tuples_test2;
use mymod::enums_test2;
use mymod::pointers_ref_test;
use mymod::structs_test2;
use mymod::guards_test;
use mymod::binding_test;
use mymod::if_let_test;
use mymod::while_let_test;
use mymod::functions_test;
use mymod::methods_test;
use mymod::closures_test;
use mymod::capturing_test;
use mymod::as_input_parameters_test;
use mymod::type_anonymity_test;
use mymod::input_functions_test;
use mymod::as_output_parameters_test;
use mymod::iterator_any_test;
use mymod::iterator_find_test;
use mymod::higher_order_functions_test;
use mymod::diverging_functions_test;
use mymod::mymod2::my3entre as my3; //别名
use mymod::base64code;
use mymod::cfg_test;
use mymod::rust_index;
use mymod::generic_test01;
use mymod::functions_test2;
use mymod::implementation_test;
use mymod::traits_test2;
use mymod::bounds_test;
use mymod::testcase_empty_bounds_test;
use mymod::multiple_bounds_test;
use mymod::where_clauses_test;
use mymod::new_type_idiom_test;
use mymod::the_problem_test;
use mymod::associated_types_test;
use mymod::phantom_type_parameters_test;
use mymod::testcase_unit_clarification_test;
use mymod::raii_test;
use mymod::ownership_and_moves_test;
use mymod::mutability_test2;
use mymod::borrowing_test;
use mymod::mutability_test3;
use mymod::freezing_test;
use mymod::aliasing_test2;
use mymod::the_ref_pattern;
use mymod::joseph2;
use mymod::lifetimes_test;
use mymod::lifetimes_explicit_annotation_test;
use mymod::lifetimes_functions;
use mymod::lifetimes_methods;
use mymod::lifetimes_structs;
use mymod::lifetimes_bounds;
use mymod::lifetimes_coercion;
use mymod::lifetimes_static;
use mymod::lifetimes_elision;
use mymod::traits_test3;
use mymod::traits_test3_derive;
use mymod::traits_test3_operator_overloading;
use mymod::traits_test3_drop;
use mymod::traits_test3_iterators;
use mymod::traits_test3_clone;
use mymod::macro_rules;
// use mymod::producers_consumers;


pub fn print_test_master(){
    println!("======== 格式化打印测试(print_test_master)========>");
    print_format_mod::print_test_01();
    println!("======== 混合数据 测试：(mymod::CompoundTypeTest::compound_type_test())========>");
    compound_type_test::compound_type_test();
    println!("======== 字面值和操作符 测试：(mymod::LiteralsAndOperators::literals_and_operators())========>");
    literals_and_operators::literals_and_operators();
    println!("======== tuples 元组 测试：(mymod::tuples::tuples())========>");
    tuples::tuples();
    println!("======== 数组和切片slices 测试：(mymod::arrays_and_slices::arrays_and_slices())========>");
    arrays_and_slices::arrays_and_slices();
    //
    println!("======== 枚举测试 enum 测试：(mod_enum_test::enum_test())========>");
    mod_enum_test::enum_test();
    println!("======== 枚举测试 enum 测试：(mod_enum_test2::enum_test_2())========>");
    mod_enum_test2::enum_test_2();
    println!("======== clike_test 测试：(clike_test::clike_test())========>");
    clike_test::clike_test();
    println!("======== 结构 structuresx 测试：(structuresx::structures_test())========>");
    structuresx::structures_test();
    println!("======== 列表？ 测试：(testcase_linked_list_test::testcase_linked_list_test())========>");
    testcase_linked_list_test::testcase_linked_list_test();
    println!("======== 静态变量和常量测试 测试：(constants_test::constants_test())========>");
    constants_test::constants_test();
    println!("======== 变量绑定 前下划线可消除编译警告 测试：(constants_test::constants_test())========>");
    variable_bindings_test::variable_bindings_test();
    println!("======== 可变变量绑定 测试：(mutability_test::mutability_test())========>");
    mutability_test::mutability_test();
    println!("======== 可变变量绑定 测试：(scope_and_shadowing_test::scope_and_shadowing_test())========>");
    scope_and_shadowing_test::scope_and_shadowing_test();
    println!("======== 声明第一 必须声明切初始化变量绑定 测试：(declare_first_test::declare_first_test())========>");
    declare_first_test::declare_first_test();
    println!("======== 类型 casting 测试：(casting_test::casting_test())========>");
    casting_test::casting_test();
    println!("======== 字面值，类同常量 literals 测试：(literals_test::literals_test())========>");
    literals_test::literals_test();
    println!("======== 推断/推论 inference 测试：(inference_test::inference_test())========>");
    inference_test::inference_test();
    println!("======== 别名 aliasing_test 测试：(aliasing_test::aliasing_test())========>");
    aliasing_test::aliasing_test();
    println!("======== 转换 测试：(conversion_from_and_into_test::conversion_from_and_into_test())========>");
    conversion_from_and_into_test::conversion_from_and_into_test();
    println!("======== 转换2字符串转换 测试：(to_and_from_strings::to_and_from_strings())========>");
    to_and_from_strings::to_and_from_strings();
    println!("======== 表达式 测试：(expressions_test::expressions_test())========>");
    expressions_test::expressions_test();
    //
    println!("======== 控制流 测试：(flow_control_test::flow_control_test())========>");
    flow_control_test::flow_control_test();
    println!("======== match 模式匹配 测试：(match_test::match_test())========>");
    match_test::match_test();
    println!("======== tuples_test2 另一个元组 测试：(tuples_test2::tuples_test2())========>");
    tuples_test2::tuples_test2();
    println!("======== enums_test2 另一个枚举 测试：(enums_test2::enums_test2())========>");
    enums_test2::enums_test2();
    println!("======== pointers_ref_test 指针引用 测试：(pointers_ref_test::pointers_ref_test())========>");
    pointers_ref_test::pointers_ref_test();
    println!("======== structs_test2 结构测试2号 测试：(structs_test2::structs_test2())========>");
    structs_test2::structs_test2();
    println!("======== guards_test 守卫 测试：(guards_test::guards_test())========>");
    guards_test::guards_test();
    println!("======== binding_test 绑定 测试：(binding_test::binding_test())========>");
    binding_test::binding_test();
    println!("======== if_let_test if let * 2  测试：(if_let_test::if_let_test[2]())========>");
    if_let_test::if_let_test();
    if_let_test::if_let_test2();
    println!("======== while_let_test while let  测试：(while_let_test::while_let_test())========>");
    while_let_test::while_let_test();
    println!("======== functions_test  测试：(functions_test::functions_test())========>");
    functions_test::functions_test();
    println!("======== methods_test  测试：(methods_test::methods_test())========>");
    methods_test::methods_test();
    //
    println!("======== closures_test 闭包  测试：(closures_test::closures_test())========>");
    closures_test::closures_test();
    println!("======== capturing_test 捕获 捕捉  测试：(capturing_test::capturing_test())========>");
    capturing_test::capturing_test();
    capturing_test::capturing_test2();
    //
    println!("========  作为输入参数  测试：(as_input_parameters_test::as_input_parameters_test())========>");
    as_input_parameters_test::as_input_parameters_test();
    println!("========  type_anonymity_test  测试：(type_anonymity_test::type_anonymity_test())========>");
    type_anonymity_test::type_anonymity_test();
    println!("========  input_functions_test  测试：(input_functions_test::input_functions_test())========>");
    input_functions_test::input_functions_test();
    println!("========  as_output_parameters_test  测试：(as_output_parameters_test::as_output_parameters_test())========>");
    as_output_parameters_test::as_output_parameters_test();
    println!("========  iterator_any_test  测试：(iterator_any_test::iterator_any_test())========>");
    iterator_any_test::iterator_any_test();
    println!("========  iterator_find_test  测试：(iterator_find_test::iterator_find_test())========>");
    iterator_find_test::iterator_find_test();
    println!("========  higher_order_functions_test  测试：(higher_order_functions_test::higher_order_functions_test())========>");
    higher_order_functions_test::higher_order_functions_test();
    println!("========  diverging_functions_test  测试：(diverging_functions_test::diverging_functions_test 123 ())========>");
    diverging_functions_test::diverging_functions_test1();
    // diverging_functions_test::diverging_functions_test2();
    diverging_functions_test::diverging_functions_test3();
    println!("========  my_mod_test mod  测试：(mymod::my_mod_test())========>");
    mymod::my_mod_test();
    println!("========  struct_visibility_mod_test mod  测试：(mm3::struct_visibility_mod_test())========>");
    mm3::struct_visibility_mod_test();
    println!("======== mm3::the_use_declaration 测试：(mm3::the_use_declaration())========>");
    mm3::the_use_declaration();
    println!("======== mm3::super_and_self_test 测试：(mm3::super_and_self_test())========>");
    mm3::super_and_self_test();
    println!("======== my3::my3entre_test 测试：(my3::my3entre_test())========>");
    println!("mymod::mymod2::my3......");
    my3::my3entre_test();
    println!("======== base64code::base64_test 测试：(base64code::base64_test())========>");
    base64code::base64_test();
    //print_other_bin();
    println!("======== cfg 配置 测试：(cfg_test::cfg_test())========>");
    cfg_test::cfg_test();
    println!("======== rust首页经典程序 测试：(rust_index::rust_index())========>");
    rust_index::rust_index();
    println!("======== generic 泛型1 测试：(generic_test01::generic_test01())========>");
    generic_test01::generic_test01();
    println!("======== 函数2 测试：(functions_test2::functions_test2())========>");
    functions_test2::functions_test2();
    println!("======== impl 实现 测试：(functions_test2::functions_test2())========>");
    implementation_test::implementation_test();
    println!("======== traits_test2 测试：(traits_test2::traits_test2())========>");
    traits_test2::traits_test2();
    println!("======== bounds_test 测试：(bounds_test::bounds_test())========>");
    bounds_test::bounds_test();
    println!("======== testcase_empty_bounds_test 测试：(testcase_empty_bounds_test::testcase_empty_bounds_test())========>");
    testcase_empty_bounds_test::testcase_empty_bounds_test();
    println!("======== multiple_bounds_test 测试：(multiple_bounds_test::multiple_bounds_test())========>");
    multiple_bounds_test::multiple_bounds_test();
    println!("======== where_clauses_test 测试：(where_clauses_test::where_clauses_test())========>");
    where_clauses_test::where_clauses_test();
    println!("======== new_type_idiom_test 测试：(new_type_idiom_test::new_type_idiom_test())========>");
    new_type_idiom_test::new_type_idiom_test();
    println!("======== the_problem_test 测试：(the_problem_test::the_problem_test())========>");
    the_problem_test::the_problem_test();
    println!("======== associated_types_test 测试：(associated_types_test::associated_types_test())========>");
    associated_types_test::associated_types_test();
    println!("======== phantom_type_parameters_test 测试：(phantom_type_parameters_test::phantom_type_parameters_test())========>");
    phantom_type_parameters_test::phantom_type_parameters_test();
    println!("======== testcase_unit_clarification_test 测试：(testcase_unit_clarification_test::testcase_unit_clarification_test())========>");
    testcase_unit_clarification_test::testcase_unit_clarification_test();
    println!("======== raii_test 测试：(raii_test::raii_test/destructor_test())========>");
    raii_test::raii_test();
    raii_test::destructor_test();
    println!("======== 所有权和所有权转移 测试：(ownership_and_moves_test::ownership_and_moves_test())========>");
    ownership_and_moves_test::ownership_and_moves_test();
    println!("======== 可变性_test2 测试：(mutability_test2::mutability_test2())========>");
    mutability_test2::mutability_test2();
    println!("======== 借用 测试：(mutability_test2::mutability_test2())========>");
    borrowing_test::borrowing_test();
    println!("======== 借用可修改 测试：(mutability_test3::mutability_test3())========>");
    mutability_test3::mutability_test3();
    println!("======== freezing 冻结 测试：(freezing_test::freezing_test())========>");
    freezing_test::freezing_test();
    println!("======== 别名 测试：(aliasing_test2::aliasing_test2())========>");
    aliasing_test2::aliasing_test2();
    println!("======== 引用模式 测试：(the_ref_pattern::the_ref_pattern())========>");
    the_ref_pattern::the_ref_pattern();
    println!("======== 变相约瑟夫环 测试：(joseph2::joseph2_test())========>");
    joseph2::joseph2_test();
    println!("======== 声明周期 测试：(lifetimes_test::lifetimes_test())========>");
    lifetimes_test::lifetimes_test();
    println!("======== 声明周期明确声明 测试：(lifetimes_explicit_annotation_test::test_fn())========>");
    lifetimes_explicit_annotation_test::test_fn();
    println!("======== 声明周期函数 测试：(lifetimes_functions::test_fn())========>");
    lifetimes_functions::test_fn();
    println!("======== 声明周期函数 测试：(lifetimes_functions::test_fn())========>");
    lifetimes_methods::test_fn();
    println!("======== 声明周期结构 测试：(lifetimes_structs::test_fn())========>");
    lifetimes_structs::test_fn();
    println!("======== 声明周期限定 测试：(lifetimes_bounds::test_fn())========>");
    lifetimes_bounds::test_fn();
    println!("======== 声明周期强制 测试：(lifetimes_coercion::test_fn())========>");
    lifetimes_coercion::test_fn();
    println!("======== 声明周期静态 测试：(lifetimes_static::test_fn())========>");
    lifetimes_static::test_fn();
    println!("======== 声明周期elision省略 测试：(lifetimes_elision::test_fn())========>");
    lifetimes_elision::test_fn();
    println!("======== 特性 测试：(traits_test3::test_fn())========>");
    traits_test3::test_fn();
    println!("======== 特性起源 测试：(traits_test3_derive::test_fn())========>");
    traits_test3_derive::test_fn();
    println!("======== 特性操作符重载 测试：(traits_test3_operator_overloading::test_fn())========>");
    traits_test3_operator_overloading::test_fn();
    println!("======== 特性 drop 释放 测试：(traits_test3_drop::test_fn())========>");
    traits_test3_drop::test_fn();
    println!("======== 特性 迭代器 测试：(traits_test3_iterators::test_fn())========>");
    traits_test3_iterators::test_fn();
    prt("特性 克隆 测试：(traits_test3_iterators::test_fn())");
    traits_test3_clone::test_fn();
    prt("宏 规则 测试：(macro_rules::test_fn())");
    macro_rules::test_fn();
    prt("宏 语法 指示器 测试：(mymod::macro_rules_designators::test_fn())");
    mymod::macro_rules_designators::test_fn();
    prt("宏 重载 指示器 测试：(mymod::macro_rules_overload::test_fn())");
    mymod::macro_rules_overload::test_fn();
    prt("生产者消费者 测试：(mymod::macro_rules_overload::test_fn())");
    // mymod::producers_consumers::producers_consumers();
    prt(" 宏 重复 测试：(mymod::macro_rules_repeat::test_fn())");
    mymod::macro_rules_repeat::test_fn();
    // mymod::macro_rules_dry::test()
    prt(" 区域特殊语言 领域特定语言 测试：(mymod::macro_rules_repeat::test_fn())");
    mymod::domain_specific_languages_dsls::test_fn();
    prt(" 可变接口 测试：(mymod::macro_rules_repeat::test_fn())");
    mymod::variadic_interfaces::test_fn();
    prt(" 转换utf8编码（可修改借用用法） 测试：(mymod::macro_rules_repeat::test_fn())");
    mymod::unicode_utf8::test_fn();
    prt(" panic 抛出错误 测试：(mymod::panic_test::test_fn())");
    mymod::panic_test::test_fn();
    prt(" option.unwrap option特殊结构 测试：(mymod::option_unwrap::test_fn())");
    mymod::option_unwrap::test_fn();
    prt(" option result 两个特殊结构 测试：(mymod::option_result_test::test_fn())");
    mymod::option_result_test::test_fn();
    prt(" 组合算子：map  组合算子（combinator）以模块化方式来管理控制流 测试：(mymod::combinator_map::test_fn())");
    mymod::combinator_map::test_fn();
    prt(" 组合算子 and_then 测试：(mymod::combinator_and_then::test_fn())");
    mymod::combinator_and_then::test_fn();
    prt(" 使用 Box 处理错误 and_then 测试：(mymod::use_box_process_err::test_fn())");
    mymod::use_box_process_err::test_fn();
    prt(" 结果 Result 测试：(mymod::result_struct::test_fn())");
    mymod::result_struct::test_fn();
    prt(" 结果 Result的map 测试：(mymod::result_struct_map::test_fn())");
    mymod::result_struct_map::test_fn();
    prt(" 结果 Result 别名 测试：(mymod::result_struct_alias::test_fn())");
    mymod::result_struct_alias::test_fn();
    prt(" 结果 Result 各种错误类型 测试：(mymod::result_struct_alias::test_fn())");
    mymod::result_many_err_type::test_fn();
    mymod::result_many_err_type::test_fn2();
    prt(" 结果 Result 提前返回 测试：(mymod::result_early_return::test_fn())");
    mymod::result_early_return::test_fn();
    prt(" try!宏 测试：(mymod::try_macro::test_fn())");
    mymod::try_macro::test_fn();
    prt(" 定义一个错误类型 测试：(mymod::make_new_err_type::test_fn())");
    mymod::make_new_err_type::test_fn();
    prt(" try! 的其他用法 测试：(mymod::try_macro_other_use::test_fn())");
    mymod::try_macro_other_use::test_fn();
    prt(" 使用 Box 处理错误(另一个) 测试：(mymod::try_macro_other_use::test_fn())");
    mymod::use_box_process_error::test_fn();
    prt(" Box, 以及栈和堆 测试：(mymod::std_box_stack::test_fn())");
    mymod::std_box_stack::test_fn();
    prt(" 动态数组 vector 测试：(mymod::strd_vector::test_fn())");
    mymod::strd_vector::test_fn();
    prt(" 字符串 String 测试：(mymod::std_string::test_fn())");
    mymod::std_string::test_fn();
    prt(" 选项 Option 测试：(mymod::std_option::test_fn())");
    mymod::std_option::test_fn();
    prt(" 结果 Result 测试：(mymod::std_result::test_fn())");
    mymod::std_result::test_fn();
    prt(" 问号操作符 测试：(mymod::question_mark_operator::test_fn())");
    mymod::question_mark_operator::test_fn();
    prt(" 散列表 HashMap 测试：(mymod::std_hash_map::test_fn())");
    mymod::std_hash_map::test_fn();
    prt(" 更改或自定义关键字类型 HashMap 测试：(mymod::change_custom_key_type::test_fn())");
    mymod::change_custom_key_type::test_fn();
    prt(" 散列集 HashSet HashMap 测试：(mymod::std_hash_set::test_fn())");
    mymod::std_hash_set::test_fn();
    prt(" 线程 测试：(mymod::std_thread::test_fn())");
    mymod::std_thread::test_fn();
    prt(" 通道 测试：(mymod::std_channel::test_fn())");
    mymod::std_channel::test_fn();
    prt(" 路径 Path 测试：(mymod::std_path::test_fn())");
    mymod::std_path::test_fn();
    prt(" 文件输入输出 I/O 测试：(mymod::std_file_io::test_fn_open/test_fn_create())");
    mymod::std_file_io::test_fn_open();
    mymod::std_file_io::test_fn_create();
    prt(" 子进程 std::process::Command执行命令行命令获取结果 测试：(mymod::sub_process::test_fn())");
    mymod::std_sub_process::test_fn();
    prt(" 命令行管道 测试：(mymod::command_channel::test_fn())");
    mymod::std_command_channel::test_fn();
    prt(" 命令行等待 Wait 测试：(mymod::command_wait::test_fn())");
    mymod::std_command_wait::test_fn();
    prt(" 文件系统操作 测试：(mymod::std_file_system::test_fn())");
    mymod::std_file_system::test_fn();
    prt(" 程序参数 测试：(mymod::std_program_args::test_fn())");
    mymod::std_program_args::test_fn();
    prt(" 参数分析 测试：(mymod::std_program_args::test_fn())");
    mymod::std_program_args::test_fn2();
    prt(" 外部语言函数接口 测试：(mymod::std_other_lang_func_interface::test_fn())");
    mymod::std_other_lang_func_interface::test_fn();
    mymod::std_other_lang_func_interface::test_fn2();
    mymod::wl_lib::X();
    
    prt("宏2 测试：mymod::macro_rules_2::test_fn()");
    mymod::macro_rules_2::test_fn();
    prt("宏2 测试：mymod::macro_rules_2::test_fn1()");
    mymod::macro_rules_2::test_fn1();
    prt("宏2 测试：mymod::macro_rules_2::test_fn2()");
    mymod::macro_rules_2::test_fn2();
    prt("宏2 测试：mymod::macro_rules_2::test_fn3()");
    mymod::macro_rules_2::test_fn3();
    prt("宏2 测试：mymod::macro_rules_2::test_fn4()");
    mymod::macro_rules_2::test_fn4();
    prt(" hyper 测试：(callhttp())");
    callhttp();
    prt(" str 相等比较 测试：( mymod::std_string::str_eq() )");
    mymod::std_string::str_eq();
    prt(" tcp 发送到服务端 测试：( mymod::tcpudp::tcpclient() )");
    mymod::tcpudp::tcpclient();
    prt(" udp 服务端 测试：( mymod::tcpudp::udpserver() )");
    mymod::tcpudp::udpserver();
    prt(" udp 服务端 测试：( mymod::tcpudp::udpclient() )");
    mymod::tcpudp::udpclient();
    prt(" 过程宏 测试：( mymod::proc_macro02::proc_macro_test() )");
    mymod::proc_macro02::proc_macro_test();
    prt(" regex 测试：( mymod::regex_text::regex_date() )");
    mymod::regex_text::regex_date();
}

/*
Rust 的核心语言中只有一种字符串类型：str
String 是标准库
*/

fn prt(msg: &str){
    println!("===== {:?} =====>", msg);
}

fn prts(msg: &String){
    println!("===== {:?} =====>", msg);
}

#[allow(dead_code)] // 加注此 特性 表示不使用的 函数代码
fn unuse_fn(){
    println!("==>{:?}<==", 234);
}


